<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 数组转对象；

    ```js

    ['a','a','a','b','b','c','c','c','c','d','d','d','d'] 

    {

        a: 3,

        b: 2,

        c: 4,

        d: 4

    }

    ``` -->
    <script>
        var arr = ['a','a','a','b','b','c','c','c','c','d','d','d','d'];
        var obj = {};
        var str = arr.join("");
            var i = 0;
            var j = 1;
            while (i < str.length) {
                if (str.charAt(i) == str.charAt(j)) {
                    j++;
                } else {
                    for (var k in arr) {
                        obj[str.charAt(i)] = j-i;
                    }
                    i = j;
                    j++;
                }
            }
        console.log(obj);
    </script>
</body>
</html>